json_data='{"name":"zhangsan","age":20}'

import json

# json格式转python格式
ret = json.loads(json_data)
print(type(json_data))
print(type(json_data))
print(type(ret))
print(ret)

# json.dump()将python对应类型转换为json格式数据
data = {'name':'zhangsan','age':20}
ret  =json.dumps(data)
print(ret)
print(type(data),type(ret))

# json.dump()将python对应类型转换为json数据格式，保存到文件
data = {"name":"zhangsan","age":20}
with open ("./json_test.txt","w",encoding="utf-8")as f:
    json.dump(data,f)
with open ("./json_test.txt","r",encoding="utf-8")as f:
    content = json.load(f)
print(content)
print(type(content))
